# 需求打开注册A.html页面，完成以下操作：
# 1.点击alert 按钮
# 2.关闭警告框
# 3.输入用户名：admin


from time import sleep

from selenium import webdriver
# 1.打开浏览器
from selenium.webdriver.support.select import Select

driver = webdriver.Chrome(executable_path='chromedriver.exe')
# driver = webdriver.Chrome() #创建浏览器对象
# 放大浏览器页面
driver.maximize_window()
# 2.输入访问地址（URL）
driver.get("http://121.43.169.97:8848/pageA.html")
# 1.点击alert 按钮
driver.find_element_by_css_selector("#alerta").click()

sleep(2)
# 获取弹框对象
al = driver.switch_to.alert
# 获取文本信息
print("警告框信息", al.text)
# 处理对话框
# 同意
al.accept()




# 2.关闭警告框
driver.find_element_by_css_selector("#userA").send_keys("admin")


driver.find_element_by_css_selector("#confirma").click()
sleep(2)
al = driver.switch_to.alert
# 取消对话框
al.dismiss()


